package com.gwtcx.sample.serendipity.client.entrypoint;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.Dictionary;
import com.google.gwt.user.client.ui.RootPanel;
import com.gwtcx.sample.serendipity.client.gin.SerendipityGinjector;
import com.gwtcx.sample.serendipity.client.i18n.SerendipityConstants;
import com.gwtcx.sample.serendipity.client.i18n.SerendipityMessages;
import com.gwtcx.sample.serendipity.client.theme.SerendipityClientBundle;
import com.gwtcx.sample.serendipity.client.util.GinUtil;
import com.gwtcx.sample.serendipity.client.util.I18nUtil;
import com.gwtplatform.mvp.client.DelayedBindRegistry;
import com.smartgwt.client.util.SC;

public abstract class MultiPageEntryPoint implements EntryPoint {
	@Override
	public void onModuleLoad() {
		GinUtil.init();
		SerendipityClientBundle.INSTANCE.css().ensureInjected();
		I18nUtil.init();   
		
		// this is required by gwt-platform proxy's generator
		DelayedBindRegistry.bind(GinUtil.getGinjector());
		
		Dictionary dictionary = Dictionary.getDictionary("Pages");
		revealCurrentPlace(dictionary.get("page"));

		// hide the animated 'loading.gif'
		RootPanel.get("loading").setVisible(false);	
	}
	
	protected abstract void revealCurrentPlace(String page);
	
	public static String getRelativeURL(String url) {
	    // .html files are located relative to the applications host page
	    // e.g. /modulename/ModuleName.html not
	    //      /modulename/modulename/hosted.html
	    return GWT.getHostPageBaseURL() + url;
	  }

	  public static SerendipityConstants getConstant() {
	    return com.gwtcx.sample.serendipity.client.util.I18nUtil.getConstant();
	  }

	  public static SerendipityMessages getMessage() {
	    return com.gwtcx.sample.serendipity.client.util.I18nUtil.getMessage();
	  }

	  public static SerendipityGinjector getSerendipityGinjector() {
	    return GinUtil.getGinjector();
	  }
}
